home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-25 | 6.3 KB | 322 lines | [TEXT/CWIE] |
- // ==================================================
- // CTouchMePref.cp
- // Copyright (C) 1996-1997 Mizutori Tetsuya
- // July 4, 1996; February 3, 1997; April 23, 1997.
- // ==================================================
- // All documents are pretty-printed in 10-point Geneva font.
-
- #pragma once
-
- #include <OSUtils.h>
-
- #include <UMemoryMgr.h>
- #include <LString.h>
-
- #include "touchMeConstants.h"
- #include "CTouchMeMainWindow.h"
- #include "CPrefsFile.h"
- #include "CTouchMePref.h"
- #include "UDateTime.h"
-
-
- const ResType PREF_ResType = 'PREF';
- const ResIDT PREF_ResID = 1000;
-
-
- // --------------------------------------------------
- // • CTouchMePref()
- // --------------------------------------------------
-
- CTouchMePref::CTouchMePref()
- {
- SetupConstants();
- }
-
-
- // --------------------------------------------------
- // • CTouchMePref()
- // --------------------------------------------------
-
- CTouchMePref::CTouchMePref(
- ConstStr255Param inFileName )
- : CPrefsFile( inFileName, kThisApplicationCreatorType )
- {
- SetupConstants();
- }
-
-
- // --------------------------------------------------
- // • ~CTouchMePref
- // --------------------------------------------------
-
- CTouchMePref::~CTouchMePref()
- {
- }
-
- // --------------------------------------------------
- // • SetupConstants
- // --------------------------------------------------
-
- void
- CTouchMePref::SetupConstants( void )
- {
- // Do nothing here.
- }
-
-
- // ==================================================
- // Member functions
- // ==================================================
-
- // --------------------------------------------------
- // • LoadPrefsData
- // --------------------------------------------------
-
- OSErr
- CTouchMePref::LoadPrefsData( void )
- {
- OSErr err;
-
- long theSizeInBytes = 0;
- StClearHandleBlock thePref( 0 );
-
- SPrefsHandle thePrefsH = (SPrefsHandle) (thePref.mHandle);
- err = LoadPrefs( theSizeInBytes, (Handle) thePrefsH, PREF_ResType, PREF_ResID );
-
- if ( err == noErr ) {
- mPrefs = **thePrefsH;
- TransformToSettings();
- }
-
- return noErr;
- }
-
-
- // --------------------------------------------------
- // • SavePrefsData
- // --------------------------------------------------
-
- OSErr
- CTouchMePref::SavePrefsData( void)
- {
- OSErr err;
-
- TransformFromSettings();
-
- long theSizeInBytes = 0;
- StClearHandleBlock thePref( 0 );
-
- SPrefsHandle thePrefsH = (SPrefsHandle) (thePref.mHandle);
- theSizeInBytes = sizeof(SPrefsRec);
-
- ::PtrToXHand( (void *) &mPrefs, (Handle) thePrefsH, theSizeInBytes );
- err = SavePrefs( theSizeInBytes, (Handle) thePrefsH, PREF_ResType, PREF_ResID );
-
- return noErr;
- }
-
-
- // --------------------------------------------------
- // • SetPrefsToWindow
- // --------------------------------------------------
- // Set the window's settings by prefs data.
-
- void
- CTouchMePref::SetPrefsToWindow(
- LWindow * inWindow )
- {
-
- switch ( inWindow->GetUserCon() ) {
-
- case CTouchMeMainWindow::class_ID:
- {
- TransformFromSettings();
- CTouchMeMainWindow * theWindow = (CTouchMeMainWindow *) inWindow;
- theWindow->SetupDialog( mPrefs );
- }
- break;
-
- }
-
- }
-
-
- // --------------------------------------------------
- // • GetPrefsFromWindow
- // --------------------------------------------------
- // Get the window's settings to prefs data.
-
- void
- CTouchMePref::GetPrefsFromWindow(
- LWindow * inWindow )
- {
-
- switch ( inWindow->GetUserCon() ) {
-
- case CTouchMeMainWindow::class_ID:
- {
- CTouchMeMainWindow * theWindow = (CTouchMeMainWindow *) inWindow;
- theWindow->InspectDialog( mPrefs );
- TransformToSettings();
- }
- break;
-
- }
-
- }
-
-
- // --------------------------------------------------
- // • TransformToSettings
- // --------------------------------------------------
-
- void
- CTouchMePref::TransformToSettings( void )
- {
- // Do nothing here.
- }
-
-
- // --------------------------------------------------
- // • TransformFromSettings
- // --------------------------------------------------
-
- void
- CTouchMePref::TransformFromSettings( void )
- {
- // Do nothing here.
- }
-
-
- // ==================================================
- // Member functions (preferences data)
- // ==================================================
- // Retrieve preferences data.
-
- // --------------------------------------------------
- // • {Set/Get}WindowRect
- // --------------------------------------------------
-
- void
- CTouchMePref::SetWindowRect(
- Rect & inWindowRect )
- {
- mPrefs.wframe = inWindowRect;
- }
-
-
- void
- CTouchMePref::GetWindowRect(
- Rect & outWindowRect )
- {
- outWindowRect = mPrefs.wframe;
- }
-
-
- // --------------------------------------------------
- // • {Set/Get}Sync
- // --------------------------------------------------
-
- void
- CTouchMePref::SetSync(
- const Boolean inStatus )
- {
- mPrefs.sync = inStatus;
- }
-
-
- Boolean
- CTouchMePref::GetSync( void )
- {
- return mPrefs.sync;
- }
-
-
- // --------------------------------------------------
- // • {Set/Get}Enabled
- // --------------------------------------------------
-
- void
- CTouchMePref::SetEnabled(
- const ETouchType inType,
- const Boolean inStatus )
- {
- mPrefs.enabled[ inType - touchType_CreationDate ] = inStatus;
- }
-
-
- Boolean
- CTouchMePref::GetEnabled(
- const ETouchType inType )
- {
- return mPrefs.enabled[ inType - touchType_CreationDate ];
- }
-
-
- // --------------------------------------------------
- // • {Set/Get}Flag
- // --------------------------------------------------
-
- void
- CTouchMePref::SetFlag(
- const ETouchType inType,
- const ETouchFlag inFlag,
- const Boolean inStatus )
- {
- if ( inStatus ) mPrefs.flag[ inType - touchType_CreationDate ] = inFlag;
- }
-
-
- Boolean
- CTouchMePref::GetFlag(
- const ETouchType inType,
- const ETouchFlag inFlag )
- {
- return ( mPrefs.flag[ inType - touchType_CreationDate ] == inFlag );
- }
-
-
- // --------------------------------------------------
- // • {Set/Get}FlagNumb
- // --------------------------------------------------
-
- void
- CTouchMePref::SetFlagNumb(
- const ETouchType inType,
- const ETouchFlag inFlag )
- {
- mPrefs.flag[ inType - touchType_CreationDate ] = inFlag;
- }
-
-
- ETouchFlag
- CTouchMePref::GetFlagNumb(
- const ETouchType inType )
- {
- return (ETouchFlag) mPrefs.flag[ inType - touchType_CreationDate ];
- }
-
-
- // --------------------------------------------------
- // • {Set/Get}DateTime
- // --------------------------------------------------
-
- void
- CTouchMePref::SetDateTime(
- const ETouchType inType,
- const unsigned long inValue)
- {
- mPrefs.datetime[ inType - touchType_CreationDate ] = inValue;
- }
-
-
- unsigned long
- CTouchMePref::GetDateTime(
- const ETouchType inType )
- {
- return mPrefs.datetime[ inType - touchType_CreationDate ];
- }
-
-
- // end of program
-